package com.sos.core
{
	import com.sos.utils.ClassUtils;

	public class LogRowType
	{

		// -------------------------------------------------------------------------------
		// CONSTANTS
		// -------------------------------------------------------------------------------		
		
		public static const DEBUG:LogRowType			= new LogRowType(1, "debug", 		0);
		public static const CAST:LogRowType				= new LogRowType(2, "cast",			1000);
		public static const CAST_INIT:LogRowType		= new LogRowType(3, "castInit",		0);
		public static const MAIN:LogRowType				= new LogRowType(4, "solveMain",	2800);		
		public static const SCORE:LogRowType			= new LogRowType(5, "solveScore",	2800);
		public static const INIT:LogRowType				= new LogRowType(6, "init",			1000);
		public static const ABILITY:LogRowType			= new LogRowType(7, "ability",		3000);
		public static const SWAP:LogRowType				= new LogRowType(8, "swap",			1500);
		public static const CAST_END:LogRowType			= new LogRowType(9, "castEnd",		4000);
		public static const DISCARD:LogRowType			= new LogRowType(10, "discard",		700);
		public static const PROC:LogRowType				= new LogRowType(11, "proc",		700);
		public static const END_MAIN:LogRowType			= new LogRowType(12, "endSolveMain",3000);
		public static const END_SCORE:LogRowType		= new LogRowType(13, "endSolveScore", 3000);
		public static const INTERRUPT:LogRowType		= new LogRowType(14, "interrupt",	3000);
		
		// -------------------------------------------------------------------------------
		// STATIC
		// -------------------------------------------------------------------------------
		
		private static var _initialized:Boolean = false;
		private static var _list:Vector.<LogRowType>;
		
		// Fake static constructor
		{
			// Fill the internal list
			_list = new Vector.<LogRowType>();
			_list.push(LogRowType.DEBUG);
			_list.push(LogRowType.CAST);
			_list.push(LogRowType.CAST_INIT);
			_list.push(LogRowType.MAIN);
			_list.push(LogRowType.SCORE);
			_list.push(LogRowType.INIT);
			_list.push(LogRowType.ABILITY);
			_list.push(LogRowType.SWAP);
			_list.push(LogRowType.CAST_END);
			_list.push(LogRowType.DISCARD);
			_list.push(LogRowType.PROC);
			_list.push(LogRowType.END_MAIN);
			_list.push(LogRowType.END_SCORE);
			_list.push(LogRowType.INTERRUPT);
			// Init!
			_initialized = true;
		}
		
		public static function getByName(name:String):LogRowType
		{
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].name == name) return _list[i];
			}
			throw new Error("LogRowType for name '" + name + "' unknown!");
		}
		
		// -------------------------------------------------------------------------------
		// FIELDS
		// -------------------------------------------------------------------------------
		
		private var _id:uint;
		private var _name:String;
		private var _delay:uint;
		
		// -------------------------------------------------------------------------------
		// CONSTRUCTORS
		// -------------------------------------------------------------------------------
		
		public function LogRowType(id:uint, name:String, delay:uint)
		{
			// Safe unique instance lock
			if (_initialized) throw new Error("LogRowType enum already created!");
			// Init
			_id    = id;
			_name  = name;
			_delay = delay;
			
		}
		
		// -------------------------------------------------------------------------------
		// PROPERTIES
		// -------------------------------------------------------------------------------		
		
		public function get id():uint
		{
			return _id;
		}
		
		public function get name():String
		{
			return _name;
		}
		
		public function get delay():uint 
		{
			return _delay;
		}
		
		
		
		
		// -------------------------------------------------------------------------------
		// PUBLIC METHODS
		// -------------------------------------------------------------------------------
		
		public function toString():String
		{
			return ClassUtils.getName(this) + "." + _name;
		}
		

		// -------------------------------------------------------------------------------
		// STATIC METHODS
		// -------------------------------------------------------------------------------
		
		/**
		 * Returns the list of the names of 
		 * @return 
		 */
		public static function names():Array
		{
			var list:Array  = new Array;
			// Loop over values list
			for (var i:int=0; i<_list.length; i++)
			{
				list.push(_list[i].name);
			}
			return list;
		}
		
		/**
		 * 
		 * @return 
		 */
		public static function list():Array
		{
			var list:Array = new Array;
			// Loop over values list
			for (var i:int=0; i<_list.length; i++)
			{
				list.push(_list[i]);
			}
			return list;
		}
		
		
	}		
		
	
}